package com.oocl.operation.impl;

import java.util.ArrayList;
import java.util.List;

import com.oocl.db.Storager;
import com.oocl.operation.OnlineUserDao;

public class OnlineUserDaoImpl implements OnlineUserDao{
	private List<String> onlineUsers;
	
	public OnlineUserDaoImpl() {
		onlineUsers = Storager.accessOnlineUsers();
	}

	@Override
	public ArrayList<String> findAll() {
		ArrayList<String> list = new ArrayList<>();
		for(int i=0;i<onlineUsers.size();i++){
			list.add(onlineUsers.get(i));
		}
		return list;
	}

	@Override
	public void add(String name) {
		if(null==name){
			return;
		}
		onlineUsers.add(name);
	}

	@Override
	public void delete(String name) {
		if(null==name){
			return;
		}
		onlineUsers.remove(name);
	}

	@Override
	public String find(String name) {
		if(null==name){
			return null;
		}
		for(String s:onlineUsers){
			if(s.equals(name)){
				return name;
			}
		}
		return null;
	}
	
}
